package org.jbox2d.testbed.tests;

import org.jbox2d.collision.shapes.CircleDef;
import org.jbox2d.collision.shapes.PolygonDef;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.testbed.AbstractExample;
import org.jbox2d.testbed.TestbedMain;

import processing.core.PImage;

public class Test1 extends AbstractExample {
	
	public PImage myImage;
	
	public Test1(TestbedMain parent){
		super(parent);
	}
	
	@Override
	public void create(){
		PolygonDef groundBoxDef = new PolygonDef();
		groundBoxDef.setAsBox(50.0f, 10.0f);
		groundBoxDef.density = 0.0f;
		
		BodyDef groundBodyDef = new BodyDef();
		groundBodyDef.position.set(0.0f, -10.0f);
		m_world.createBody(groundBodyDef).createShape(groundBoxDef);
		
		PolygonDef boxDef = new PolygonDef();
		boxDef.setAsBox(1.0f, 1.0f);
		boxDef.density = 1.0f;
		boxDef.friction = 0.3f;
		boxDef.restitution = 0.3f;
		
		BodyDef bodyDef = new BodyDef();
		bodyDef.position.set(-10-3.0f+0*2.5f, 30.0f);
		
		Body box = m_world.createBody(bodyDef);
		box.createShape(boxDef);
		box.setMassFromShapes();
		box.setAngularVelocity(parent.random(-0.5f, 0.5f));
		
		CircleDef circleDef = new CircleDef();
		circleDef.density = 1.0f;
		circleDef.friction = 0.3f;
		boxDef.restitution = 0.1f;
		
		BodyDef bodyDef2 = new BodyDef();
		bodyDef2.position.set(-10-3.0f+0*2.5f,40.f);
		bodyDef2.isBullet = true;
		
		Body circle = m_world.createBody(bodyDef2);
		circle.createShape(circleDef);
		circle.setMassFromShapes();
		
		myImage = parent.loadImage("exp3.png");
		Vec2 localOffset = new Vec2(0.0f, 0f);
		
		float scale = 1.9f/myImage.width;
		float rot = 0f;
		bindImage(myImage, localOffset, rot, scale, box);			
	}
	
	@Override
	public 	String getName(){
		return "Test1";		
	}
	
}
